package cn.kgc.service;

import cn.kgc.dao.UserDao;
import cn.kgc.dao.UserDaoImpl;
import cn.kgc.pojo.User;
import cn.kgc.util.DataBaseUtil_single;
import cn.kgc.util.DatabaseUtil;

import java.sql.Connection;
import java.sql.SQLException;

public class UserServiceImpl implements  UserService {

    UserDao userDao =new UserDaoImpl();


    @Override
    public User login(String name, String password) {
        Connection conn= DataBaseUtil_single.getInstance().getConnect();
        try {
            User user =userDao.getUserByName(conn,name);
            if(user!=null&&user.getPassword().equals(password)){
                return user;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DatabaseUtil.closeResult(conn,null,null);
        }
        return null;
    }
}
